package com.yueka.controller;

import com.yueka.pojo.Result;
import com.yueka.pojo.student.Student;
import com.yueka.pojo.student.StudentQueryParam;
import com.yueka.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/student")
@RestController
public class StudentController {

    @Autowired
    StudentService studentService;
    @GetMapping("/list")
    public Result getStudentList(StudentQueryParam studentQueryParam) {
        try {
            System.out.println(studentQueryParam);
            return Result.success(studentService.getStudentList(studentQueryParam));
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @GetMapping("/getInIds")
    public Result getInIds(Integer[] ids) {
        try {
            return Result.success(studentService.getInIds(ids));
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/insert")
    public Result insertStudent(@RequestBody Student student) {
        try {
            studentService.insertStudent(student);
            return Result.success();
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/update")
    public Result updateStudent(@RequestBody Student student) {
        try {
            studentService.updateStudent(student);
            return Result.success();
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/login")
    public Result login(@RequestBody Student student) {
        try {
            return Result.success(studentService.login(student));
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }
}
